package cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordDO;
import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordConvert;
import cn.iocoder.yudao.module.biz.service.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordService;

@Api(tags = "管理后台 - 演练记录")
@RestController
@RequestMapping("/biz/emergency-reserve-plain-drill-record")
@Validated
public class BizEmergencyReservePlainDrillRecordController {

    @Resource
    private BizEmergencyReservePlainDrillRecordService emergencyReservePlainDrillRecordService;

    @PostMapping("/create")
    @ApiOperation("创建演练记录")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:create')")
    public CommonResult<String> createEmergencyReservePlainDrillRecord(@Valid @RequestBody BizEmergencyReservePlainDrillRecordCreateReqVO createReqVO) {
        return success(emergencyReservePlainDrillRecordService.createEmergencyReservePlainDrillRecord(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新演练记录")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:update')")
    public CommonResult<Boolean> updateEmergencyReservePlainDrillRecord(@Valid @RequestBody BizEmergencyReservePlainDrillRecordUpdateReqVO updateReqVO) {
        emergencyReservePlainDrillRecordService.updateEmergencyReservePlainDrillRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除演练记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:delete')")
    public CommonResult<Boolean> deleteEmergencyReservePlainDrillRecord(@RequestParam("id") String id) {
        emergencyReservePlainDrillRecordService.deleteEmergencyReservePlainDrillRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得演练记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:query')")
    public CommonResult<BizEmergencyReservePlainDrillRecordRespVO> getEmergencyReservePlainDrillRecord(@RequestParam("id") String id) {
        BizEmergencyReservePlainDrillRecordDO emergencyReservePlainDrillRecord = emergencyReservePlainDrillRecordService.getEmergencyReservePlainDrillRecord(id);
        return success(BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convert(emergencyReservePlainDrillRecord));
    }

    @GetMapping("/list")
    @ApiOperation("获得演练记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:query')")
    public CommonResult<List<BizEmergencyReservePlainDrillRecordRespVO>> getEmergencyReservePlainDrillRecordList(@RequestParam("ids") Collection<String> ids) {
        List<BizEmergencyReservePlainDrillRecordDO> list = emergencyReservePlainDrillRecordService.getEmergencyReservePlainDrillRecordList(ids);
        return success(BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得演练记录分页")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:query')")
    public CommonResult<PageResult<BizEmergencyReservePlainDrillRecordRespVO>> getEmergencyReservePlainDrillRecordPage(@Valid BizEmergencyReservePlainDrillRecordPageReqVO pageVO) {
        PageResult<BizEmergencyReservePlainDrillRecordDO> pageResult = emergencyReservePlainDrillRecordService.getEmergencyReservePlainDrillRecordPage(pageVO);
        return success(BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出演练记录 Excel")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill-record:export')")
    @OperateLog(type = EXPORT)
    public void exportEmergencyReservePlainDrillRecordExcel(@Valid BizEmergencyReservePlainDrillRecordExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizEmergencyReservePlainDrillRecordDO> list = emergencyReservePlainDrillRecordService.getEmergencyReservePlainDrillRecordList(exportReqVO);
        // 导出 Excel
        List<BizEmergencyReservePlainDrillRecordExcelVO> datas = BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "演练记录.xls", "数据", BizEmergencyReservePlainDrillRecordExcelVO.class, datas);
    }

}
